package cn.torna.tornaexample.controller.product;

import cn.torna.tornaexample.common.Result;
import cn.torna.tornaexample.controller.product.param.SubParam;
import cn.torna.tornaexample.controller.product.param.VideoStructuredAnalysisTasksDTO;
import cn.torna.tornaexample.controller.product.vo.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.io.IOUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Date;

@Tag(name = "测试用例")
@RestController
public class Example2021922Controller {

    @Operation(summary = "example2021922")
    @PostMapping("example2021922")
    public ResponseEntity a(@RequestBody VideoStructuredAnalysisTasksDTO dto) {
        return null;
    }


    @Operation(summary = "delete method with body")
    @DeleteMapping("2021111/delete")
    public Result delete(HttpServletRequest request) {
        try {
            ServletInputStream inputStream = request.getInputStream();
            String body = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
            return Result.ok(body);
        } catch (IOException e) {
            e.printStackTrace();
            return Result.error("参数错误");
        }
    }

    /**
     * 2021111/400?date=2021-11-233
     * @return
     */
    @Operation(summary = "模拟400错误")
    @GetMapping("2021111/400")
    public Result error400(@Schema(description = "日期", example = "2021-11-233") Date date) {
        return Result.ok(date);
    }

    /**
     * 参数继承有Map<String, Object>
     * @return
     */
    @Operation(summary = "参数继承有Map<String, Object>")
    @GetMapping("20220704/1")
    public PageInfo demo20220704(SubParam param) {
        PageInfo pageInfo = new PageInfo();
        return pageInfo;
    }

}
